package com.gxa.eshop.portal.controller;

import com.gxa.eshop.core.exception.BusinessException;
import com.gxa.eshop.core.pojo.Banner;
import com.gxa.eshop.core.utils.JsonResult;
import com.gxa.eshop.portal.service.BannerService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/banner")
public class BannerController {

    @Resource
    BannerService bannerService;

    @PostMapping("/getAll")
    public JsonResult getAll(@RequestParam("position") String postion) throws BusinessException {

        List<Banner> banners = bannerService.selectAllByPosition(postion);
        JsonResult jsonResult = new JsonResult();
        if(banners.size()>0){
            jsonResult.setCode("1");
            jsonResult.setData(banners);
        }else{
            throw  new BusinessException("没有符合条件的广告图");
        }

        return jsonResult;
    }
}
